package com.xxx.sevice;

import com.xxx.mapper.UserMapper;
import com.xxx.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class addUserlistimpl implements UserMapper {
    @Override
    public ArrayList<String> addUser(User user) throws IOException {
        final InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        //创建会话工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        try (SqlSession session = sqlSessionFactory.openSession()) {
            final UserMapper mapper = session.getMapper(UserMapper.class);
            final ArrayList<String> list = mapper.addUser(user);
            final int i = session.insert("list", list);
            session.commit();
            System.out.println("i = " + i);
        }

        return null;
    }
}